import Mock from 'mockjs'
import { param2Obj } from './utils'

export default {
  list: () => {
    const items = Mock.mock({
      'items|30': [{
        id: '@id',
        title: '@sentence(10, 20)',
        'status|1': ['published', 'draft', 'deleted'],
        author: 'name',
        display_time: '@datetime',
        pageviews: '@integer(300, 5000)'
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  team: () => {
    const items = Mock.mock({
      'items|30': [{
        id: '@id',
        title: '@sentence(10, 20)',
        leader: '@name',
        members: '@integer(0,100)',
        topicnum: '@integer(0,1000)',
        response: '@integer(0,500)',
        'status|1': ['已开启', '已关闭']
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  topic: () => {
    const items = Mock.mock({
      'items|30': [{
        id: '@id',
        title: '@sentence(10, 20)',
        'property|1': ['置顶', '加精'],
        creator: '@name',
        team: '@integer(0,100)',
        response: '@integer(0,500)',
        'status|1': ['已开启', '已关闭']
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  inviteRecord: () => {
    const items = Mock.mock({
      'items|30': [{
        person: '@name',
        user: '@name',
        'cost|1-1000.2': 1,
        'coin|1-1000.2': 1,
        'money|1-1000.2': 1,
        code: '@string(16)',
        date: '@datetime'
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  rewardRecord: () => {
    const items = Mock.mock({
      'items|30': [{
        username: '@name',
        getTime: '@datetime',
        'face|1-1000.2': 1,
        'useMsg|1': ['已使用', '未使用'],
        onTime: '@datetime',
        orderMsg: '@string(7)',
        'rewardType|1': ['注册奖励', '邀请奖励']
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  batchList: (param) => {
    const { batchType } = param2Obj(param.url)
    let items = ''
    const preparation = Mock.mock({
      startDate: '@date(yyyy-MM-dd)',
      endDate: '@date(yyyy-MM-dd)',
      'usedNum|1-100': 1,
      'receivedNum|1-100': 1,
      'sum|1-100': 1
    })
    if (batchType === 'coupon') {
      items = Mock.mock({
        'items|30': [{
          id: '@id',
          codename: '@name',
          precode: '@word(5)',
          codemsg: '@sentence(4)',
          usedTotal: preparation.usedNum + '/' + preparation.receivedNum + '/' + preparation.sum,
          util: preparation.startDate + '~' + preparation.endDate,
          'decost|1-1000.2': 1,
          'trench|1': ['通过链接', '通过优惠码']
        }]
      })
    } else if (batchType === 'studyCard') {
      items = Mock.mock({
        'items|30': [{
          id: '@id',
          code: '@String(16)',
          'codeType|1': ['课程', '班级', '会员', '全站'],
          'codeStatus|1': ['已使用', '未使用'],
          targetName: '@cname',
          orderInfo: '@cparagraph(1)',
          content: '@cparagraph(1)',
          'originalPrice|1-100': 1,
          'actualPayment|1-100': 1,
          batchName: '@cparagraph(1)',
          receiveTime: '@datetime',
          orderTime: '@datetime'
        }]
      })
    }

    return {
      code: 200,
      data: items
    }
  },
  courseList: () => {
    const items = Mock.mock({
      'items|30': [{
        id: '@id',
        courseName: '@sentence(4,15)',
        'number|1-100': 1,
        'status|1': ['已发布', '未发布', '回收站'],
        creator: '@cname'
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  classList: () => {
    const items = Mock.mock({
      'items|30': [{
        id: '@id',
        className: '@sentence(4,15)',
        'number|1-100': 1,
        'price|1-10000.2': 1,
        'status|1': ['已发布', '未发布', '回收站']
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  memberList: () => {
    const items = Mock.mock({
      'items|30': [{
        id: '@id',
        memberName: '@sentence(4,15)'
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  info: () => {
    const items = Mock.mock({
      'items|60': [{
        id: '@id(1,5)',
        title: '@sentence(4,15)',
        'categoryId|1': ['行业动向', '学院连线', '学院新闻'],
        updateTime: '@date',
        'status|1': ['已发布', '未发布', '回收站'],
        'sticky|1': [true, false]
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  // 系统日志
  biaodanTable: () => {
    const items = Mock.mock({
      'items|60': [{
        'grade|1': ['提醒', ''],
        'user|1': ['教育', 'admin'],
        'operation|1': ['登录成功', '更新了'],
        'business|1': ['用户', '系统设置'],
        time: '@id',
        IPaddress: '@id'
      }]
    })
    return {
      code: 200,
      data: items
    }
  },
  // 系统自检
  zijianLable: () => {
    const items = Mock.mock({
      'items|60': [{
        'Environmental|1': ['PHP版本', '安全模式'],
        'configure|1': ['Linux', '关闭'],
        'state|1': ['关闭', '12秒'],
        'requirement|1': ['30秒', '必须']
      }]
    })
    return {
      code: 200,
      data: items
    }
  }
}
